package vip.xiaonuo.smzq.core.utils;

import vip.xiaonuo.auth.core.pojo.SaBaseLoginUser;
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;

/**
 * 用户工具类
 *
 * @author Kevin
 * @since 2024/7/20 11:27
 */
public class UserUtil {

    //默认河北省行政区划代码
    private static final String DEFAULT_XZQHDM = "130000";
    private static final String ORG_ID_ZERO = "0";
    private static final String ORG_ID_MINUS_ONE = "-1";

    /**
     * 获取当前登录用户的行政区划代码前缀
     *
     * @author Kevin
     * @since 2024/7/20 11:27
     */
    public static String getCurrentUserXzqhdm() {
        SaBaseLoginUser saBaseLoginUser = StpLoginUserUtil.getLoginUser();
        String xzqhdm = "";
        if (saBaseLoginUser.getOrgId() == null && saBaseLoginUser.getOrgId().length() == 0) {
            xzqhdm = DEFAULT_XZQHDM;
        } else if (ORG_ID_ZERO.equals(saBaseLoginUser.getOrgId()) || ORG_ID_MINUS_ONE.equals(saBaseLoginUser.getOrgId())) {
            xzqhdm = DEFAULT_XZQHDM;
        } else {
            xzqhdm = saBaseLoginUser.getOrgId();
        }
        xzqhdm = xzqhdm.replaceAll("0+$", "");
        return xzqhdm;
    }
    /**
     * 获取当前登录用户的行政区划代码
     *
     * @author Kevin
     * @since 2024/7/20 11:27
     */
    public static String getCurrentUserXzqhdmNoInterception() {
        SaBaseLoginUser saBaseLoginUser = StpLoginUserUtil.getLoginUser();
        String xzqhdm = "";
        if (saBaseLoginUser.getOrgId() == null && saBaseLoginUser.getOrgId().length() == 0) {
            xzqhdm = DEFAULT_XZQHDM;
        } else if (ORG_ID_ZERO.equals(saBaseLoginUser.getOrgId()) || ORG_ID_MINUS_ONE.equals(saBaseLoginUser.getOrgId())) {
            xzqhdm = DEFAULT_XZQHDM;
        } else {
            xzqhdm = saBaseLoginUser.getOrgId();
        }
//        xzqhdm = xzqhdm.replaceAll("0+$", "");
        return xzqhdm;
    }
}
